﻿<?xml version="1.0" encoding="utf-8"?>
<!--
	This is an attempt to build a valid XSD file from the XMLRPC spec defined at
	http://www.xmlrpc.com/spec
	
	You are free to use this in any way you see fit as long as you keep this notice intact.
	
	This file is presented as is, and Bambit Technologies in no way guarantees the accruacy, completeness
	or beauty of this file.
	
	Copyright: Bambit Technologies, Inc. 2009
	
	
	History: 
	===============================================================
	2009.07.08 - Law Metzler - Version: 0.1
	Created
	2009.07.16 - Law Metzler - Version: 0.2
	Added some min/max constraints (more probably needed)
	===============================================================
	
-->
<xs:schema 
	id="xmlRpc" 
	elementFormDefault="qualified" 
	xmlns:xs="http://www.w3.org/2001/XMLSchema"
>
	<!-- 
		One of two possible roots, method call is what is sent to the RPC server.  it consists
		strictly of the method name and the parameters associated with it.
	-->
	<xs:element name="methodCall">
		<xs:complexType>
			<xs:sequence>
				<xs:element name="methodName" type="xs:string" minOccurs="1" maxOccurs="1"/>
				<xs:element name="params" minOccurs="1" maxOccurs="1">
					<xs:complexType>
						<xs:sequence minOccurs="0" maxOccurs="unbounded">
							<xs:element name="param" type="parameter"/>
						</xs:sequence>
					</xs:complexType>
				</xs:element>
			</xs:sequence>
		</xs:complexType>
	</xs:element>
	
	<xs:element name="methodResponse">
		<xs:complexType>
			<xs:choice>
				<xs:element name="params" type="param"/>
				<xs:element name="fault" type="fault"/>
			</xs:choice>
		</xs:complexType>
	</xs:element>

	<xs:complexType name="fault">
		<xs:sequence minOccurs="1" maxOccurs="1">
			<xs:element name="value">
				<xs:complexType>
					<xs:sequence maxOccurs="1" minOccurs="1">
						<xs:element name="value" type="faultValue" />
					</xs:sequence>
				</xs:complexType>
			</xs:element>
		</xs:sequence>
	</xs:complexType>

	<xs:complexType name="faultValue">
		<xs:sequence maxOccurs="1" minOccurs="1">
			<xs:element name="struct" type="faultStruct"/>
		</xs:sequence>
	</xs:complexType>

	<xs:complexType name="faultStruct">
		<xs:sequence maxOccurs="2" minOccurs="2">
			<xs:element name="member">
				<xs:complexType>
					<xs:sequence maxOccurs="2" minOccurs="2">
						<xs:element name="name" type="xs:string"/>
						<xs:element name="value" type="value" />
					</xs:sequence>
				</xs:complexType>
			</xs:element>
		</xs:sequence>
	</xs:complexType>
	<!-- 
		Represents a parameter passed into a function.  Parameters do NOT contain names, just
		values
	-->
	<xs:complexType name="parameter">
		<xs:sequence>
			<xs:element type="value" name="value"  minOccurs="0" maxOccurs="1" />
		</xs:sequence>
	</xs:complexType>

	<!-- 
		Represnts a value.  Values generally specicy the type of value. If it does NOT specify 
		the type of value, it defaults to string
	-->
	<xs:complexType mixed="true" name="value" >
		<xs:choice  minOccurs="0" maxOccurs="1" >
			<xs:element name="i4" type="xs:int" />
			<xs:element name="int" type="xs:int" />
			<xs:element name="boolean" type="xs:boolean"/>
			<xs:element name="string" type="xs:string" />
			<xs:element name="double" type="xs:double" />
			<xs:element name="dateTime.iso8601" type="xs:dateTime" />
			<xs:element name="base64" type="xs:base64Binary" />
			<xs:element name="struct" type="struct"/>
			<xs:element name="array" type="array"/>
		</xs:choice>
	</xs:complexType>
	
	<!-- 
		One of the non-standard XML value types, arrays contain a single element, "data", which
		contains multiple instances of values (mixed values at that)
	-->
	<xs:complexType name="array">
		<xs:sequence>
			<xs:element name="data">
				<xs:complexType>
					<xs:sequence minOccurs="1" maxOccurs="unbounded">
						<xs:element name="value" type="value"/>
					</xs:sequence>
				</xs:complexType>
			</xs:element>
		</xs:sequence>
	</xs:complexType>

	<!--
		One of the non-standard XML value types, structs contain multiple memebr values
	-->
	<xs:complexType name="struct">
		<xs:sequence minOccurs="1" maxOccurs="unbounded">
			<xs:element type="member" name="member"/>
		</xs:sequence>
	</xs:complexType>

	<!--
		Part of the definition of a struct, a member is a named values
	-->
	<xs:complexType name="member">
		<xs:sequence>
			<xs:element name="name" type="xs:string"/>
			<xs:element type="value" name="value"/>
		</xs:sequence>
	</xs:complexType >
</xs:schema>
